<?php

namespace app\oa\model;
/**
 * @author: yfl
 * @QQ: 554665488
 * @description:  工作汇报表模型
 * @time: 2017年7月10日 16:48:43
 * Class Report
 * @package app\oa\model
 */
class Report extends Base
{

    // 开启自动写入时间戳字段
    protected $autoWriteTimestamp = true;
    // 设置返回数据集的对象名
    protected $resultSetType = 'collection';

    //定义相对的关联
    public function user()
    {
        return $this->belongsTo('user');
    }

    /**
     * @author: yfl
     * @QQ: 554665488
     * @description: 下拉加载获得数据
     * @time: 2017年7月12日 10:06:573
     * @param $user_data
     * @param $start
     * @return false|\PDOStatement|string|\think\Collection
     */
    static public function getReportInfoByUid($user_data, $start)
    {
        return self::where(array('user_id' => $user_data['uid'], 'duty_id_level' => array('elt', $user_data['duty_info']['level'])))
            ->alias('r')
            ->field('r.*,u.realname')
            ->join('oa_user u', 'r.user_id=u.uid')
            ->order('id DESC')
            ->limit($start . ',10')->select();
    }

    /**
     * @author: yfl
     * @QQ: 554665488
     * @description: 获得可以查看的数量
     * @time: 2017-7-12 10:09:15
     * @param $user_data
     * @return int|string
     */
    static public function getReportInfoByUidCount($user_data)
    {
        return self::where(array('user_id' => $user_data['uid'], 'duty_id_level' => array('elt', $user_data['duty_info']['level'])))->count('id');
    }

    /**
     * @author: yfl
     * @QQ: 554665488
     * @description: 搜索获得数据
     * @time: 2017年7月19日 10:37:44
     * @param $user_data
     * @param $start
     * @return false|\PDOStatement|string|\think\Collection
     */
    public function getSearchInfoByUid($user_data,$start)
    {
//        return self::where(array('user_id' => $user_data['uid'], 'duty_id_level' => array('elt', $user_data['duty_info']['level'])))
        return self::where(array('user_id' => $user_data['uid']))
            ->alias('r')
            ->field('r.*,u.realname')
            ->join('oa_user u', 'r.user_id=u.uid')
            ->order('id DESC')
            ->limit($start . ',20')->select();
    }

    /**
     * @author: yfl
     * @QQ: 554665488
     * @description:根据关键词获得搜索的内容
     * @time: 2017-7-18 09:41:40
     * @param $search
     * @return false|\PDOStatement|string|\think\Collection
     */
    public function getSearchInfoByContext($search)
    {
        return $this->whereLike('context','%'.$search.'%')->select();
    }
}
